﻿package  plugins.mstandio.AS3Interface.layouts{
	
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.events.MouseEvent;	
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	
	import plugins.mstandio.AS3Interface.AS3Interface;
	import plugins.mstandio.AS3Interface.buttons.InterfaceButton;
	import plugins.mstandio.AS3Interface.images.ImageEmbeder;
	import plugins.mstandio.utils.combobox.ComboBox;
	import plugins.mstandio.utils.combobox.ComboBoxStyle;
	
	
	/**	 
	 * @author mstandio
	 */
	public class Layout extends Sprite implements LayoutInterface{														
		
		protected var layoutObject:Object;		
		protected var brandBar:Sprite;
		
		//basic elements 
		protected var button_up:InterfaceButton;
		protected var button_down:InterfaceButton;
		protected var button_left:InterfaceButton;
		protected var button_right:InterfaceButton;
		protected var button_zoomin:InterfaceButton;
		protected var button_zoomout:InterfaceButton;
		protected var button_autorotate:InterfaceButton;
		protected var button_fullscreen:InterfaceButton;                           
		protected var button_universalmap:InterfaceButton;		
		protected var comboBox:ComboBox;
		
		public function Layout(layoutObject:Object){
			this.layoutObject = layoutObject;	
			this.button_up = this.layoutObject[AS3Interface.BUTTON_UP];
			this.button_down = this.layoutObject[AS3Interface.BUTTON_DOWN];
			this.button_left = this.layoutObject[AS3Interface.BUTTON_LEFT];
			this.button_right = this.layoutObject[AS3Interface.BUTTON_RIGHT];
			this.button_zoomin = this.layoutObject[AS3Interface.BUTTON_ZOOMIN];
			this.button_zoomout = this.layoutObject[AS3Interface.BUTTON_ZOOMOUT];
			this.button_autorotate = this.layoutObject[AS3Interface.BUTTON_AUTOROTATE];
			this.button_fullscreen = this.layoutObject[AS3Interface.BUTTON_FULLSCREEN];
			this.button_universalmap = this.layoutObject[AS3Interface.BUTTON_UNIVERSALMAP];
			this.comboBox = this.layoutObject[AS3Interface.COMBOBOX];
			
			this.buildBrandBar();
		}		
		
		public function handleStageResize():void { };		
		
		protected function buildBrandBar(alpha:Number=0.3):void {			
			this.brandBar = new Sprite();						
			this.brandBar.alpha = alpha; 
			var brand1:Bitmap = new Bitmap(new ImageEmbeder.Bitmap_branding_poweredby().bitmapData, "auto", true);
			var brand2:Bitmap = new Bitmap(new ImageEmbeder.Bitmap_branding_panosalado().bitmapData, "auto", true);
			var brand3:Bitmap = new Bitmap(new ImageEmbeder.Bitmap_branding_universalmap().bitmapData, "auto", true);									
			
			var link1:Sprite = new Sprite();
			link1.addChild(brand2);
			link1.buttonMode = true;
			link1.useHandCursor = true;
			
			var link2:Sprite = new Sprite();
			link2.buttonMode = true;
			link2.useHandCursor = true;
			link2.addChild(brand3);
			
			this.brandBar.addChild(brand1);
			this.brandBar.addChild(link1);
			this.brandBar.addChild(link2);						
			
			brand1.x = 0;
			link1.x = brand1.x + brand1.width;
			link2.x = link1.x + link1.width;			
			
			link1.addEventListener(MouseEvent.MOUSE_DOWN, this.gotoPanoSalado, false, 0, true);			
			link2.addEventListener(MouseEvent.MOUSE_DOWN, this.gotoUniversalMap, false, 0, true);
		}		
		
		
		private function gotoUniversalMap(e:MouseEvent=null):void {						
			var request:URLRequest = new URLRequest("http://code.google.com/p/universalmap/");
			try {
				navigateToURL(request, '_BLANK');
			} catch (e:Error) {
				// doh
			}
		}
		
		private function gotoPanoSalado(e:MouseEvent = null):void {			
			var request:URLRequest = new URLRequest("http://panosalado.com/");			
			try {
				navigateToURL(request, '_BLANK');
			} catch (e:Error) {
				// doh
			}
		}	
	}	
}